from django.contrib import admin
from msgs.models import *

class GivingBackInline(admin.TabularInline):
	model = Reading
	extra = 0

	def queryset(self, request):
		qs = Reading.objects.filter(status='B')
		return qs

class ReservingInline(admin.TabularInline):
	model = Reserving
	extra = 0

	def queryset(self, request):
		qs = Reserving.objects.filter(status='C')
		return qs

class CheckInOutAdmin(admin.ModelAdmin):
	inlines = [GivingBackInline, ReservingInline]
	list_display = ['user', 'num_check_in', 'num_check_out']

	def num_check_in(self, obj):
		return Reserving.objects.filter(status='C').count()

	def num_check_out(self, obj):
		return Reading.objects.filter(status='B').count()

admin.site.register(CheckInOut, CheckInOutAdmin)
